#include<iostream>
#include<algorithm>
using namespace std;
struct mv
{
    int s;
    int e;
}jie[100];
bool cmp(mv u,mv v){
    return u.e<v.e;//从低到高排序
}
int main(){
    int n;
    while(cin>>n&&n!=0){
        for(int i=0;i<n;i++){
            cin>>jie[i].s>>jie[i].e;
        }
        sort(jie,jie+n,cmp);
        int amp=1,temp=0;
        for(int i=0;i<n;i++){
            if(jie[temp].e<=jie[i].s){
                amp++;
                temp=i;
            }
        }
        cout<<amp<<endl;
    }
}